package com.itheima.common.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.itheima.common.exception.enums.ResponseEnum;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {

    private Boolean success; //业务执行是否成功
    private int code;        //返回状态码
    private String message;  //提示消息
    private T data;          //返回数据 可能是对象 集合 简单类型


    public Result() {
    }

    public Result(Boolean success, int code) {
        this.success = success;
        this.code = code;
    }

    public Result(Boolean success, int code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public Result(Boolean success, int code, T data) {
        this.success = success;
        this.code = code;
        this.data = data;
    }

    public Result(Boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static <T> Result<T> success() {
        return new Result<T>(true, ResponseEnum.SUCCESS.getCode());
    }

    public static <T> Result<T> successMessage(String message) {
        return new Result<T>(true, ResponseEnum.SUCCESS.getCode(), message);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(true, ResponseEnum.SUCCESS.getCode(), data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(true, ResponseEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Result<T> error() {
        return new Result<T>(false, ResponseEnum.ERROR.getCode(), ResponseEnum.ERROR.getMessage());
    }

    public static <T> Result<T> errorMessage(String errorMessage) {
        return new Result<T>(false, ResponseEnum.ERROR.getCode(), errorMessage);
    }

    public static <T> Result<T> errorCodeMessage(int errorCode, String errorMessage) {
        return new Result<T>(false, errorCode, errorMessage);
    }

}
